package com.ksyun.campus.client.domain;

/**
 * Standard API response
 */
public class ApiResponse<T> {
    
    private boolean ok;
    private String message;
    private T data;
    private String code;
    private String leader; // for NOT_LEADER responses
    
    public ApiResponse() {
    }
    
    public ApiResponse(boolean ok, String message, T data, String code, String leader) {
        this.ok = ok;
        this.message = message;
        this.data = data;
        this.code = code;
        this.leader = leader;
    }
    
    public static <T> ApiResponse<T> success(T data) {
        return new ApiResponse<>(true, null, data, null, null);
    }
    
    public static <T> ApiResponse<T> success() {
        return new ApiResponse<>(true, null, null, null, null);
    }
    
    public static <T> ApiResponse<T> error(String message) {
        return new ApiResponse<>(false, message, null, null, null);
    }
    
    public static <T> ApiResponse<T> notLeader(String leader) {
        return new ApiResponse<>(false, "Current node is not leader", null, "NOT_LEADER", leader);
    }
    
    // Getters and Setters
    public boolean isOk() {
        return ok;
    }
    
    public void setOk(boolean ok) {
        this.ok = ok;
    }
    
    public String getMessage() {
        return message;
    }
    
    public void setMessage(String message) {
        this.message = message;
    }
    
    public T getData() {
        return data;
    }
    
    public void setData(T data) {
        this.data = data;
    }
    
    public String getCode() {
        return code;
    }
    
    public void setCode(String code) {
        this.code = code;
    }
    
    public String getLeader() {
        return leader;
    }
    
    public void setLeader(String leader) {
        this.leader = leader;
    }
    
    // 为了兼容性，添加isSuccess方法
    public boolean isSuccess() {
        return ok;
    }
}
